package icegps.com.pingdj.map.draw;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;

import icegps.com.pingdj.App;
import icegps.com.pingdj.R;
import icegps.com.pingdj.map.bean.MapStatus;


/**
 * Created by 111 on 2018/3/5.
 */

public class DrawPoint {
    private Paint pointPaint;
    private MapStatus mapStatus;
    private Bitmap point;
    private int width = 0;
    private int height = 0;

    public DrawPoint(MapStatus mapStatus) {
        Drawable drawable = App.getInstance().getResources().getDrawable(R.drawable.svg_point);
        point = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(point);
        drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
        drawable.draw(canvas);
        if (point != null) {
            width = point.getWidth();
            height = point.getHeight();
        }
        this.mapStatus = mapStatus;
        pointPaint = new Paint();
    }

    /**
     * 绘制当前位置点
     *
     * @param canvas
     */
    public void drawPoint(Canvas canvas) {
        float x = mapStatus.getCx() * mapStatus.getMultiple() - width / 2;
        float y = mapStatus.getCy() * mapStatus.getMultiple() - height / 2;
        //位置点在地图缩放过程中始终保持原来大小
        canvas.scale(1.0f / mapStatus.getMultiple(), 1.0f / mapStatus.getMultiple(), mapStatus.getMx(), mapStatus.getMy());
        canvas.rotate(mapStatus.getAngle(), mapStatus.getCx() * mapStatus.getMultiple(), mapStatus.getCy() * mapStatus.getMultiple());
        canvas.drawBitmap(point, x, y, pointPaint);
        canvas.rotate(-mapStatus.getAngle(), mapStatus.getCx() * mapStatus.getMultiple(), mapStatus.getCy() * mapStatus.getMultiple());
    }
}
